package com.lagou.stage1.module3.task2;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class Worker {

    //(1)定义一个Worker类型(属性私有、空参有参构造、set、get方法、toString方法、equals方法、hashCode方法)，包含三个属性：姓名(String name)、年龄(int age)、工资(double salary),在Worker类中定义work方法打印一句话，如："凤姐 正在工作"，其中"凤姐"代表当前对象的姓名
    //定义三个属性：姓名(String name)、年龄(int age)、工资(double salary)
    private String name;
    private int age;
    private double salary;

    //空参,有参构造
    public Worker() {
    }

    public Worker(String name, int age, double salary) {
        setName(name);
        setAge(age);
        setSalary(salary);
    }

    //set、get方法
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    //重写toString方法
    @Override
    public String toString() {
        return "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }

    //重写equals方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Worker worker = (Worker) o;
        return age == worker.age && Double.compare(worker.salary, salary) == 0 && (this.name == worker.name);
        }

    //重写hashCode方法
    @Override
    public int hashCode() {
        return Objects.hash(name, age, salary);
    }

    //定义work方法
    public void work() {
        System.out.println(name + "正在工作!");
    }

}
